package com.soft.javase.day02.practice.order;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/16
 */
// 订单类
class Order {
    private long orderId;
    private User owner;
    private Goods[] goodsList;
    private int goodsCount;

    public Order(long orderId, User owner, int maxGoods) {
        this.orderId = orderId;
        this.owner = owner;
        this.goodsList = new Goods[maxGoods];
        this.goodsCount = 0;
    }

    // 添加商品到订单
    public void addGoods(Goods goods) {
        if (goodsCount < goodsList.length) {
            goodsList[goodsCount] = goods;
            goodsCount++;
        } else {
            System.out.println("订单已满，无法添加更多商品！");
        }
    }

    public void showGoodsDetails() {
        System.out.println("订单号: " + orderId);
        System.out.println("所属用户: " + owner.getName());
        System.out.println("商品列表:");

        double total = 0;
        for (int i = 0; i < goodsCount; i++) {
            System.out.println("---------------------");
            System.out.println("商品 " + (i+1));
            goodsList[i].showInfo();
            total += goodsList[i].getPrice() * goodsList[i].getQuantity();
        }

        System.out.println("---------------------");
        System.out.println("订单总金额: " + total+"\n");
    }

    public long getOrderId() { return orderId; }
}

